<?php
class settingModel extends baseModel{

	//保存配置
	public function save_config($app, $new_config = array()){
		if( !is_file($app) ){
			$file = BASE_PATH . 'apps/' . $app. '/config.php';
		}else{
			$file = $app;
		}

		if( is_file($file) ) {
			$config = require($file);
			$config = array_merge($config, $new_config);
		}else{
			$config = $new_config;
		}

		$content = var_export($config, true);
		$content = str_replace("_PATH' => '" . addslashes(BASE_PATH), "_PATH' => BASE_PATH . '", $content);

		if( file_put_contents($file, "<?php \r\nreturn " . $content . ';' ) ) {
			return true;
		}
		return false;
	}

	//获取模板内容
    public function tpl_list()
    {
        $tpl_dir=realpath(ROOT_PATH.'themes/'.config('TPL_TEMPLATE_NAME'));
        $list_file=scandir($tpl_dir);
        if(is_array($list_file)){
        	$list=array();
	        foreach ($list_file as $value) {
	            if ($value != "." && $value != "..") {
	                $list[]=$value;
	            }
	        }
        }
        return $list;
    }

    //获取模板路径
    public function themes_list()
    {
        $tpl_dir=realpath(ROOT_PATH.'themes/');
        $list_file=scandir($tpl_dir);
        if(is_array($list_file)){
        $list=array();
	        foreach ($list_file as $value) {
	            if ($value != "." && $value != ".."&&!strpos($value,".")) {
	                $list[]=$value;
	            }
	        }
        }
        return $list;
    }


}